import style from "./loading.module.less"; //loading指令自创
import loadingUIL from "../assets/loading.svg";
export default function(el, binding) {
    const curImg = getLoadingImg(el);
    if (binding.value) {
        if (!curImg) {
            const img = creatLoadingImg();
            el.appendChild(img);
        }
    } else {
        if (curImg) {
            curImg.remove();
        }

    }


}

function getLoadingImg(el) {
    return el.querySelector("img[data-role=loading]");
}
//创建img
function creatLoadingImg() {
    const img = document.createElement('img');
    img.src = loadingUIL;
    img.dataset.role = 'loading';
    img.className = style.loading;
    return img;
}